/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
// -*- coding:iso-8859-15 mode: c++ -*-
/** 
 * \file
 * \brief MaCI_SpeedCtrl Player for logged data
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 *
 * $Id: SpeedCtrlFilePlayer.hpp,v 1.3 2009-06-05 14:04:45 morsko Exp $
 *
 */
#ifndef _SPEEDCTRLFILEPLAYER_HPP_
#define _SPEEDCTRLFILEPLAYER_HPP_
#include <string>
#include <map>
#include <vector>
#include <list>
#include "PlayerModule.hpp"
#include "owndebug.h"
#include "ownutils.h"
#include "gimutils.h"
#include "SpeedCtrlServer.hpp"

class SpeedCtrlFilePlayer: public PlayerModule
{
public:

  /**
   * Constructor
   * 
   * @param aSpeedCtrlServer    Pointer to speedCtrl server
   * @param aFilename           full path to file
   */
  SpeedCtrlFilePlayer(MaCI::SpeedCtrl::CSpeedCtrlServer *aSpeedCtrlServer,
                    std::string aFilename);

  /**
   * Destructor
   * NOTE: the speedCtrlServer pointer is deleted here!
   */
  virtual ~SpeedCtrlFilePlayer();

  /**
   * REturns action times
   *
   * @param aTimes times of action 
   */
  bool GetTimes(std::list<gim::time> *aTimes);

  /**
   * Sends speedCtrl data of wanted time
   *
   * @param aTime Time of data to be sent
   * @return true if data found 
   */
  bool OnTime(gim::time aTime);

  /** 
   * Return name of instance
   *
   * @return name of instance
   */
  std::string GetName(void);

  /**
   * Returns begin and ending times of this player module
   *
   * @param aBegin Time of beginning
   * @param aEnd   Time of ending
   */
  void GetTimeLimits(gim::time &aBegin,gim::time &aEnd);
private:

  /**
   * Reads data from file and saved it to iData -map
   */
  bool ReadData();

  MaCI::SpeedCtrl::CSpeedCtrlServer *iSpeedCtrlServer;         ///< Pointer to speedctrlserver
  std::map<gim::time,MaCI::SpeedCtrl::CSpeedCtrlData *> iData; ///< map of data got from file
  std::list<gim::time> iTimes;                                 ///< times of actions
  gim::time iBegin;                                            ///< Begin time
  gim::time iEnd;                                              ///< End time
  FILE *iFile;                                                 ///< Pointer to file
  std::string iName;                                           ///< Name of instance

  //*****************************************************************************
  SpeedCtrlFilePlayer(const SpeedCtrlFilePlayer&)
    :PlayerModule(),
     iSpeedCtrlServer(NULL),
     iData(),
     iTimes(),
     iBegin(),
     iEnd(),
     iFile(NULL),
     iName(""){}

  SpeedCtrlFilePlayer &operator=(const SpeedCtrlFilePlayer&) { return *this; }
  //*****************************************************************************
};

#endif
